Data Visualization¶
In [14]:
# %pip install -U leafmap lonboard
In [2]:
import leafmap
Visualizing point data.
In [3]:
url = 'https://open.gishub.org/data/duckdb/cities.parquet'
Read GeoParquet and return a GeoPandas GeoDataFrame.
In [4]:
gdf = leafmap.read_parquet(url, return_type='gdf', src_crs='EPSG:4326')
gdf.head()
Out[4]:
| country | id | latitude | longitude | name | population | geometry | |
|---|---|---|---|---|---|---|---|
| 0 | UGA | 1.0 | 0.5833 | 32.5333 | Bombo | 75000.0 | POINT (32.53330 0.58330) |
| 1 | UGA | 2.0 | 0.6710 | 30.2750 | Fort Portal | 42670.0 | POINT (30.27500 0.67100) |
| 2 | ITA | 3.0 | 40.6420 | 15.7990 | Potenza | 69060.0 | POINT (15.79900 40.64200) |
| 3 | ITA | 4.0 | 41.5630 | 14.6560 | Campobasso | 50762.0 | POINT (14.65600 41.56300) |
| 4 | ITA | 5.0 | 45.7370 | 7.3150 | Aosta | 34062.0 | POINT (7.31500 45.73700) |
View the GeoDataFrame interactively using folium.
In [5]:
gdf.explore()
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Visualize the GeoDataFrame using lonboard.
In [6]:
leafmap.view_vector(gdf, get_radius=20000, get_fill_color='blue')
Out[6]:
Map(layers=[ScatterplotLayer(get_fill_color=(0, 0, 255, 255), get_radius=20000.0, table=pyarrow.Table country:…
Visualizing polygon data.
In [7]:
url = 'https://data.source.coop/giswqs/nwi/wetlands/DC_Wetlands.parquet'
In [8]:
gdf = leafmap.read_parquet(url, return_type='gdf', src_crs='EPSG:5070', dst_crs='EPSG:4326')
gdf.head()
Out[8]:
| ATTRIBUTE | WETLAND_TYPE | ACRES | Shape_Length | Shape_Area | geometry | |
|---|---|---|---|---|---|---|
| 0 | PEM5Ax | Freshwater Emergent Wetland | 0.454008 | 621.865659 | 1837.304895 | MULTIPOLYGON (((-76.88117 38.98540, -76.88112 ... |
| 1 | PFO1A | Freshwater Forested/Shrub Wetland | 3.339719 | 586.449553 | 13515.364977 | MULTIPOLYGON (((-76.88955 38.98061, -76.88950 ... |
| 2 | PUBHh | Freshwater Pond | 0.873177 | 335.425439 | 3533.620783 | MULTIPOLYGON (((-76.87580 38.98168, -76.87571 ... |
| 3 | R4SBC | Riverine | 0.788316 | 1078.745304 | 3190.202659 | MULTIPOLYGON (((-76.87603 38.98196, -76.87607 ... |
| 4 | R4SBC | Riverine | 0.069572 | 106.791860 | 281.546217 | MULTIPOLYGON (((-76.87472 38.98170, -76.87484 ... |
In [9]:
gdf.explore()
Out[9]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [10]:
leafmap.view_vector(gdf, get_fill_color=[0, 0, 255, 128])
Out[10]:
Map(layers=[SolidPolygonLayer(get_fill_color=[0, 0, 255, 128], table=pyarrow.Table ATTRIBUTE: string WETLAND_T…
Alternatively, you can specify a color map to visualize the data.
In [11]:
color_map = {
"Freshwater Forested/Shrub Wetland": (0, 136, 55),
"Freshwater Emergent Wetland": (127, 195, 28),
"Freshwater Pond": (104, 140, 192),
"Estuarine and Marine Wetland": (102, 194, 165),
"Riverine": (1, 144, 191),
"Lake": (19, 0, 124),
"Estuarine and Marine Deepwater": (0, 124, 136),
"Other Freshwater Wetland": (178, 134, 86),
}
In [12]:
leafmap.view_vector(gdf, color_column='WETLAND_TYPE', color_map=color_map, opacity=0.5)
Out[12]:
Map(layers=[SolidPolygonLayer(get_fill_color=<pyarrow.lib.FixedSizeListArray object at 0x0000016278736320> [ …
Display a legend for the data.
In [13]:
leafmap.Legend(title="Wetland Type", legend_dict=color_map)
Out[13]:
Legend(children=(VBox(children=(HBox(children=(ToggleButton(value=True, icon='bars', layout=Layout(height='28p…